perf(android): [SDK Overhead Reduction 3] Reuse SentryExecutorService for DeviceInfoUtil pre-caching#5502
Conversation
…hing Replace Executors.newSingleThreadExecutor() with options.getExecutorService() in DefaultAndroidEventProcessor to avoid creating a dedicated thread during init. The SDK already has an executor service available.
📲 Install BuildsAndroid
|
|
the change looks good to me (still would prefer not to spawn threads when unnecessary), but i'd be curious where the slowness comes from. Could you check the actual flamegraph in perfetto? |
Will do, likely tomorrow. |
|
@romtsn I just checked the perfetto traces and it basically sums up to: Depending on the device and its load this might add a significant chunk to startup. Maybe loading this lazily is an option, I'll investigate a bit more. |
|
A quick investigation suggests we'd be running the risk of ANRs when doing this work lazily on first use since it might run on main thread then. I still wanted to investigate whether we could add async event processing. This would be a good candidate to move but might also be a breaking change for customers who expect the info to already be present when their callbacks kick in. |

PR Stack (SDK Overhead Reduction)
📜 Description
Replace
Executors.newSingleThreadExecutor()withoptions.getExecutorService()inDefaultAndroidEventProcessorfor theDeviceInfoUtilpre-caching task. This avoids creating a dedicated thread + executor during SDK init when the SDK already has an executor service available. Also removes theexecutorService.shutdown()call since we don't own the shared executor.💡 Motivation and Context
Part of the SDK Overhead Reduction stack. During Android SDK init,
DefaultAndroidEventProcessorwas creating its ownSingleThreadExecutorjust to submit one task for pre-caching device info. The SDK's executor service (SentryExecutorService) is already available at this point and can handle this work without the overhead of spinning up an additional thread pool.💚 How did you test it?
./gradlew :sentry-android-core:compileDebugUnitTestJavaWithJavac— compiles successfully./gradlew spotlessApply apiDump— no API surface changes📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
More SDK overhead reduction PRs in this stack.
#skip-changelog